package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.common.condition;

import org.apache.commons.lang3.BooleanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author lilh
 * @date 2019-02-20 23:55
 */
public class FouraCondition extends SpringBootCondition {

    private static final String FOUR_A_ENABLE_KEY = "4a.enable";

    @Override
    public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        if (!BooleanUtils.toBooleanObject(environment.getProperty(FOUR_A_ENABLE_KEY, Boolean.FALSE.toString()))) {
            return ConditionOutcome.noMatch("关闭4a配置");
        }

        return ConditionOutcome.match("启用4a配置");
    }
}
